// 毫秒
export class CDTimer {
    private lastUseTimestamp: number = 0
    private cdMillisecond: number

    // 设置cd
    resetCD(millisecond: number) {
        this.cdMillisecond = millisecond
    }

    // 获取cd
    getCD(): number {
        return this.cdMillisecond || 0.001
    }

    // 获取剩余CD
    getLeftTime() {
        return Math.max(0, this.lastUseTimestamp + this.getCD() - Date.now())
    }

    // 能不能用, 返回能用就用了
    canUse(): boolean {
        let currentTime = Date.now()
        if ((this.lastUseTimestamp + this.getCD()) > currentTime) return false
        return true
    }

    // 记录当前时间
    mark(){
        let currentTime = Date.now()
        this.lastUseTimestamp = currentTime
    }
}